package com.pnnd;

import com.pnnd.utils.NeedInit;

import java.util.List;

public abstract class DTypeObject implements NeedInit {

    protected String name;
    protected int typeNum;
    protected String typeStr;
    protected boolean fixLength;
    protected int elementLength;
    protected boolean baseType;

    protected DTypeObject(String name,String typeStr,int typeNum,int elementLength){
        this.name = name;
        this.typeStr = typeStr;
        this.typeNum = typeNum;
        this.elementLength = elementLength;
        this.fixLength = false;
        this.baseType = true;
    }

    protected DTypeObject(String name,String typeStr,int typeNum){
        this.name = name;
        this.typeStr = typeStr;
        this.typeNum = typeNum;
        this.fixLength = true;
        this.elementLength = -1;
        this.baseType = true;
    }

    public abstract Class<?> getJvmKlass();

    public boolean isFixLength() {
        return fixLength;
    }

    public int getElementLength() {
        return elementLength;
    }

    public int getTypeNum() {
        return typeNum;
    }

    public String getTypeStr() {
        return typeStr;
    }

    @Override
    public void init(){
        NdEnvironment.nameDTypeMap.put(this.name,this);
        NdEnvironment.baseTypeStrDTypeMap.put(this.getTypeStr(),this);
    }

    public List<DTypeObject> getSubTypes(){
        return null;
    }

    /**
     * 是否为基元类型
     */
    public boolean isBaseType() {
        return baseType;
    }

//    public static class Builder{
//
//
//        private Class klass;
//        private String name;
//        private String typeStr;
//        private int typeNum;
//        private int elementLength;
//
//        public Builder setClass(Class klass){
//            this.klass = klass;
//            return this;
//        }
//
//        public DTypeObject build(){
//            return new DTypeObject() {
//                @Override
//                public Class<?> getJvmKlass() {
//                    return null;
//                }
//
//                @Override
//                public NeedInit create() {
//                    return null;
//                }
//            }
//        }
//
//    }
}
